<?php
class Wb {

	private static $config;
	
	public static function getConfig() {
		self::loadConfig();
		return self::$config;
	}
	
	public static function getAddableModules() {
		self::loadConfig();
		$list = array();
		foreach( self::$config['modules'] as $key => $conf ) {
			if( $conf['addable'] == true ) {
				$list[$key] = $conf['name'];
			}
		}
		return $list;
	}
	
	public static function getModuleName( $className ) {
		self::loadConfig();
		return self::$config['modules'][$className]['name'];
	}
	
	public static function getModuleConfig( $className ) {
		self::loadConfig();
		return self::$config['modules'][$className];
	}
	
	private static function loadConfig() {
		if( self::$config == NULL ) {
			$confPath = DOM_CONF_DIR_PATH.'webBase.conf.php';
			if( is_file($confPath) ) {
				require(DOM_CONF_DIR_PATH.'webBase.conf.php');
				self::$config = $WB_CONF;
			} else {
				throw new RuntimeException('Wb config file does not exist. It should be found here: '.$confPath);
			}
		}
	}
	
	public static function createTables() {
		WbSite::getTable()->update();
		foreach( self::getAddableModules() as $className => $conf ) {
			call_user_func(array($className,'getTable'))->update();
		}
	}

}